var main = new Vue({
	el: '#main',
	data: {
		ip:localStorage.ip,
		loading:'',
		pagNamb:0,
		titles: ["待接单","未领取", "已领取", "已送达"],
		isActive: 1,
		oldMenName:"",//老人姓名
		response_0:[],
		response: [],
		response2: [],
		response3: []

	},
	methods:{
		openurl:function(n,info){
			sessionStorage.drugstyle=n;
			sessionStorage.druginfo=JSON.stringify(info);
			window.location.href='drug.html'
		},
		switchstate:function(n){
			this.isActive = n;
			this.loading='';
			this.pagNamb=0;
			this.response_0.length=0;
			this.response.length=0;
			this.response2.length=0;
			this.response3.length=0;
			if(n == 2){
				yiyaoList(2)
			}else if(n==3){
				yiyaoList(3)
			}else if(n==4){
				yiyaoList(4)
			}else if(n==1){
				waiting();
			}
		},
		onScroll:function(ref){
			if(this.$refs[ref].scrollTop+this.$refs[ref].clientHeight >= this.$refs[ref].scrollHeight-2){
				if(this.isActive == 1){
					waiting(this.oldname,this.pagNamb)
				}else{
					yiyaoList(this.isActive,this.pagNamb)
				}
			}
		}
	},
	watch: {
	    oldMenName:function(){
		    	this.loading="";
		    	waitingName(this.oldMenName)
	    }
	}
})


function yiyaoList(type,pageNo){
	if(!main.loading){
		main.loading="正在加载 . . .";
		ajaxPost(
			Url.ASSESS_DEUGLIST,
			{
				"pageNo":pageNo||"0",
				"pageSize":"10",
				"type":type
			},
			function(data){
				if(data.status==1){
					main.pagNamb+=1;
					if(data.response.length == 0 || data.response.length<10){
						main.loading="没有更多了。。。"
					}else{
						main.loading='';
					}
					if(type==2){
						for(var i=0;i<data.response.length;i++){
							main.response.push(data.response[i])
						}
					}else if(type==3){
						for(var i=0;i<data.response.length;i++){
							main.response2.push(data.response[i])
						}
					}else if(type==4){
						for(var i=0;i<data.response.length;i++){
							main.response3.push(data.response[i])
						}
					}
				}else{
					main.loading="";
				}
			},
			function(){
				main.loading="";
			}
		)
	}
}
//ASSESS_WAIT
var timeid=null;
function waitingName(nameold){
	console.log("chuan1"+nameold);
	clearTimeout(timeid);
	main.response_0.length=0;
	timeid=setTimeout(function(){waiting(nameold)},1000)	
}

function waiting(oldname,pageNo){
	document.getElementById("main").setAttribute("style","display: block;");
	if(!main.loading){
		main.loading="正在加载 . . .";
		ajaxPost(
			Url.ASSESS_WAIT,
			{
				"pageNo":pageNo||"0",
				"pageSize":"10",
				"name":oldname||""
			},
			function(data){
				document.getElementById("main").setAttribute("style","display: block;");
				console.log(data)
				if(data.status==1){
					main.pagNamb+=1;
					for(var i=0;i<data.response.length;i++){
						main.response_0.push(data.response[i])
					}
					if(data.response.length == 0 || data.response.length<10){
						main.loading="没有更多了。。。"
					}else{
						main.loading='';
					}
				}
			},
			function(){
				main.loading="";
			}
		)
	}
}
waiting()